package moo.stargalaxy_bukkit.utils;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

public class CommandUtil {
    public CommandUtil() {
    }
    // 命令别名功能
    public static void executeCommand(Player player, String cmd) {
        cmd = cmd.replace("%p%", player.getName());
        cmd = cmd.replace("%player%", player.getName());
        cmd = cmd.replaceAll("<player>", player.getName());
        //String type = cmd.toLowerCase();
        if (cmd.startsWith("[op]")) { // 判断是否用管理员身份
            boolean isOp = player.isOp();
            try {
                player.setOp(true);
                player.chat("/" + cmd.substring(4).trim());
            } catch (Throwable var8) {
                var8.printStackTrace();
            } finally {
                player.setOp(isOp);
            }
        } else if (cmd.startsWith("[console]")) { // 判断是否用后台执行
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd.substring(9).trim());
        } else { // 都不是就是玩家身份执行
            player.chat("/" + cmd.trim());
        }

    }
}